/*
 * Copyright (c) 2009, Servoy-stuff
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 * http://www.fsf.org/licensing/licenses/lgpl.txt
 */
package net.stuff.servoy.beans.slider.wicket;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.math.BigDecimal;

import javax.swing.border.Border;


import net.stuff.servoy.beans.slider.IServoySliderBean;
import net.stuff.servoy.beans.slider.ServoyUtils;

//import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.convert.IConverter;

import com.servoy.j2db.Messages;
import com.servoy.j2db.dataprocessing.IFoundSet;
import com.servoy.j2db.dataprocessing.IRecord;
import com.servoy.j2db.plugins.IClientPluginAccess;
import com.servoy.j2db.server.headlessclient.dataui.ChangesRecorder;
import com.servoy.j2db.server.headlessclient.dataui.StyleAttributeModifierModel;
import com.servoy.j2db.server.headlessclient.dataui.TooltipAttributeModifier;
import com.servoy.j2db.server.headlessclient.dataui.WebComponentSpecialIdMaker;
import com.servoy.j2db.ui.IProviderStylePropertyChanges;
import com.servoy.j2db.ui.IStylePropertyChanges;
import com.servoy.j2db.ui.ISupportWebBounds;
import com.servoy.j2db.util.ComponentFactoryHelper;
import com.servoy.j2db.util.PersistHelper;
import com.servoy.j2db.util.Utils;

/**
 * @author Servoy Stuff
 * http://www.servoy-stuff.net/
 */
public class ServoyWicketSlider extends Panel implements IServoySliderBean, ISupportWebBounds, IProviderStylePropertyChanges {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Insets insets = new Insets(2,2,2,2);
	public ChangesRecorder jsChangeRecorder = new ChangesRecorder(insets, new Insets(0,0,0,0));

	private Dimension size;
	private Border border;
	private Point location;
	private Color background;
	private Color foreground;
	private Font font;
	private String toolTipText;
	private String name;
	private boolean opaque;
	protected Cursor cursor;

	protected IFoundSet currentFoundset;
	protected IRecord currentRecord;
	protected boolean validationEnabled = true;
	protected double previousValue;
	private String dataProviderID;

	private double numberValue;
	
	private boolean focusable;
	private int orientation;
	private boolean inverted;
	private int minimumValue;
	private int maximumValue;
	private int majorTicks;
	private int minorTicks;
	private boolean paintTicks;
	private boolean paintLabels;
	private boolean paintTrack;
	private boolean snapToTicks;
	private int precision;
	private boolean usingDecimals;
	
	private String webStyleType;
	
	private String onDataChange;
	private IClientPluginAccess app;
	
	/**
	 * @param id
	 */
	public ServoyWicketSlider(String id, String webStyleType) {
		super(id);
		this.webStyleType = webStyleType;
		
		setNumberValue(0);
		
	    add(StyleAttributeModifierModel.INSTANCE);
	    add(TooltipAttributeModifier.INSTANCE);
	    
		setOutputMarkupPlaceholderTag(true);
		setVersioned(false);
	    setOutputMarkupId(true);
	    
	    TextField field = new TextField("slider-input", new PropertyModel(this, "numberValue"), Double.class) {
			private static final long serialVersionUID = 1L;

			@Override
	    	public IConverter getConverter(Class c) {
	    		return new SliderDoubleConverter();
	    	}
	    };
	    field.setMarkupId("slider-input-"+getId());
	    field.setOutputMarkupId(true);	    
	    add(field);
		
	    field.add(new SliderUpdatingBehavior(SliderUpdatingBehavior.DATA_CHANGE, this));
	    field.add(new SliderUpdatingBehavior(SliderUpdatingBehavior.LOST_FOCUS, this));
	    
	    TextField backing = new TextField("slider-backing", new PropertyModel(this, "numberValue"), Double.class) {
	    	private static final long serialVersionUID = 1L;

			@Override
	    	public IConverter getConverter(Class c) {
	    		return new SliderDoubleConverter();
	    	}
	    };
	    backing.setMarkupId("slider-backing-"+getId());
	    backing.setOutputMarkupId(true);
	    add(backing);
	    add(new SliderScriptingBehavior(this));
	}
	
	@Override
	public String getMarkupId() {
		return WebComponentSpecialIdMaker.getSpecialIdIfAppropriate(this);//getId();
	}
	
	/*
	@Override
	protected void onRender(MarkupStream markupStream) {
		super.onRender(markupStream);
		jsChangeRecorder.setRendered();
	}
	*/
		
	/* (non-Javadoc)
	 * @see org.apache.wicket.Component#onAfterRender()
	 */
	@Override
	protected void onAfterRender() {
		super.onAfterRender();
		jsChangeRecorder.setRendered();
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getCurrentValue()
	 */
	public int getCurrentValue() {
		Number n = getNumberValue();
		return (n == null) ? 0 : n.intValue();
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getDataProviderID()
	 */
	public String getDataProviderID() {
		return dataProviderID;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getInverted()
	 */
	public boolean getInverted() {
		return inverted;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getMajorTicks()
	 */
	public int getMajorTicks() {
		return majorTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getMaximumValue()
	 */
	public int getMaximumValue() {
		return maximumValue;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getMinimumValue()
	 */
	public int getMinimumValue() {
		return minimumValue;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getMinorTicks()
	 */
	public int getMinorTicks() {
		return minorTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getOrientation()
	 */
	public int getOrientation() {
		return orientation;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getPaintLabels()
	 */
	public boolean getPaintLabels() {
		return paintLabels;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getPaintTicks()
	 */
	public boolean getPaintTicks() {
		return paintTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getPaintTrack()
	 */
	public boolean getPaintTrack() {
		return paintTrack;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getPrecision()
	 */
	public int getPrecision() {
		return precision;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getSnapToTicks()
	 */
	public boolean getSnapToTicks() {
		return snapToTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#getToolTipMessage()
	 */
	public String getToolTipMessage() {
		return toolTipText;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#isFocusable()
	 */
	public boolean isFocusable() {
		return focusable;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#isUsingDecimals()
	 */
	public boolean isUsingDecimals() {
		return usingDecimals;
	}
	
	private boolean isUsingFactor() {
		return isUsingDecimals() && hasDataProvider();
	}
	
	private boolean hasDataProvider() {
		return ServoyUtils.isNotEmpty(getDataProviderID());
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setCurrentValue(int)
	 */
	public void setCurrentValue(int currentValue) {
		setNumberValue(currentValue*(Math.pow(10.0, getPrecision())));

	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setDataProviderID(java.lang.String)
	 */
	public void setDataProviderID(String dataProviderID) {
		this.dataProviderID = dataProviderID;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setFocusable(boolean)
	 */
	public void setFocusable(boolean focusable) {
		this.focusable = focusable;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setInverted(boolean)
	 */
	public void setInverted(boolean inverted) {
		this.inverted = inverted;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setMajorTicks(int)
	 */
	public void setMajorTicks(int majorTicks) {
		this.majorTicks = majorTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setMaximumValue(int)
	 */
	public void setMaximumValue(int maximumValue) {
		this.maximumValue = maximumValue;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setMinimumValue(int)
	 */
	public void setMinimumValue(int minimumValue) {
		this.minimumValue = minimumValue;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setMinorTicks(int)
	 */
	public void setMinorTicks(int minorTicks) {
		this.minorTicks = minorTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setOrientation(int)
	 */
	public void setOrientation(int orientation) {
		this.orientation = orientation;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setPaintLabels(boolean)
	 */
	public void setPaintLabels(boolean paintLabels) {
		this.paintLabels = paintLabels;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setPaintTicks(boolean)
	 */
	public void setPaintTicks(boolean paintTicks) {
		this.paintTicks = paintTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setPaintTrack(boolean)
	 */
	public void setPaintTrack(boolean paintTrack) {
		this.paintTrack = paintTrack;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setPrecision(int)
	 */
	public void setPrecision(int precision) {
		this.precision = precision;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setSnapToTicks(boolean)
	 */
	public void setSnapToTicks(boolean snapToTicks) {
		this.snapToTicks = snapToTicks;
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setToolTipMessage(java.lang.String)
	 */
	public void setToolTipMessage(String toolTipMessage) {
		setToolTipText(Messages.getStringIfPrefix(toolTipMessage));
	}

	/* (non-Javadoc)
	 * @see net.stuff.servoy.beans.slider.IServoySliderBean#setUsingDecimals(boolean)
	 */
	public void setUsingDecimals(boolean usingDecimals) {
		this.usingDecimals = usingDecimals;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getBackground()
	 */
	public Color getBackground() {
		return background;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getBorder()
	 */
	public Border getBorder() {
		return border;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getFont()
	 */
	public Font getFont() {
		return font;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getForeground()
	 */
	public Color getForeground() {
		return foreground;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getLocation()
	 */
	public Point getLocation() {
		return location;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getName()
	 */
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getSize()
	 */
	public Dimension getSize() {
		return size;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#getToolTipText()
	 */
	public String getToolTipText() {
		return toolTipText;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#isOpaque()
	 */
	public boolean isOpaque() {
		return opaque;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setBackground(java.awt.Color)
	 */
	public void setBackground(Color c) {
		this.background = c;
		if (c != null) {
			jsChangeRecorder.setBgcolor(PersistHelper.createColorString(c));
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setBorder(javax.swing.border.Border)
	 */
	public void setBorder(Border border) {
		this.border = border;
		if (this.border != null) {
			ComponentFactoryHelper.createBorderCSSProperties(ComponentFactoryHelper.createBorderString(this.border), jsChangeRecorder.getChanges());
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setComponentEnabled(boolean)
	 */
	public void setComponentEnabled(boolean enabled) {
		setEnabled(enabled);
		jsChangeRecorder.setChanged();
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setComponentVisible(boolean)
	 */
	public void setComponentVisible(boolean visible) {
		setVisible(visible);
		jsChangeRecorder.setVisible(visible);
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setCursor(java.awt.Cursor)
	 */
	public void setCursor(Cursor cursor) {
		this.cursor = cursor;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setFont(java.awt.Font)
	 */
	public void setFont(Font font) {
		this.font = font;
		if (font != null) {
			jsChangeRecorder.setFont(PersistHelper.createFontString(font));
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setForeground(java.awt.Color)
	 */
	public void setForeground(Color c) {
		this.foreground = c;
		if (c != null) {
			jsChangeRecorder.setFgcolor(PersistHelper.createColorString(c));
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setLocation(java.awt.Point)
	 */
	public void setLocation(Point location) {
		this.location = location;
		if (this.location != null) {
			jsChangeRecorder.setLocation(location.x, location.y);
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setName(java.lang.String)
	 */
	public void setName(String name) {
		this.name = name;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setOpaque(boolean)
	 */
	public void setOpaque(boolean b) {
		this.opaque = b;
		jsChangeRecorder.setTransparent(!b);
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setSize(java.awt.Dimension)
	 */
	public void setSize(Dimension size) {
		this.size = size;
		if (this.size != null) {
			jsChangeRecorder.setSize(size.width, size.height, this.border, null, 0);
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IComponent#setToolTipText(java.lang.String)
	 */
	public void setToolTipText(String toolTipText) {
		this.toolTipText = toolTipText;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.dataui.IServoyAwareBean#initialize(com.servoy.j2db.plugins.IClientPluginAccess)
	 */
	public void initialize(IClientPluginAccess app) {
		this.app = app;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.dataui.IServoyAwareBean#setSelectedRecord(com.servoy.j2db.dataprocessing.IRecord)
	 */
	public void setSelectedRecord(IRecord record) {
		if (record != null) {
			this.currentFoundset = record.getParentFoundSet();
			this.currentRecord = record;
			updateSlider();
		}
	}

	/**
	 * 
	 */
	private void updateSlider() {
		if (ServoyUtils.isExisting(currentFoundset, currentRecord)) {
			if (ServoyUtils.isContainedInFoundset(currentRecord,getDataProviderID())) {
				Object o = currentRecord.getValue(getDataProviderID());
				if (o == null) o = new Double(0.0);
				if (o instanceof BigDecimal) o = new Double(((BigDecimal)o).doubleValue());
				this.numberValue = (Double)o;
				this.previousValue = getNumberValue();
			} else {
				if (validationEnabled) {
					setMinimumValue(1);
					int max = currentFoundset.getSize();
					setMaximumValue(max);
					setMajorTicks(max-1);
					int tickSpacing = Math.max(Math.round(max/10),1);
					setMinorTicks(tickSpacing);
					this.numberValue = currentFoundset.getSelectedIndex()+1;
					this.previousValue = getNumberValue();
				} else {
					setMinimumValue(0);
					this.numberValue = 0;
					this.previousValue = getNumberValue();
				}
			}
			jsChangeRecorder.setChanged();
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.dataprocessing.IDisplay#isReadOnly()
	 */
	public boolean isReadOnly() {
		return !isEnabled();
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.dataprocessing.IDisplay#setValidationEnabled(boolean)
	 */
	public void setValidationEnabled(boolean validationEnabled) {
		this.validationEnabled = validationEnabled;
		if (!hasDataProvider()) {
			setEnabled(validationEnabled);
		}
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.dataprocessing.IDisplay#stopUIEditing(boolean)
	 */
	public boolean stopUIEditing(boolean paramBoolean) {
		return true;
	}

	/**
	 * @return the numberValue
	 */
	public double getNumberValue() {
		return this.numberValue;
	}

	/**
	 * @param numberValue the numberValue to set
	 */
	public void setNumberValue(double numberValue) {
		this.numberValue = numberValue;
		if (previousValue != numberValue) {
			if (ServoyUtils.isExisting(currentFoundset, currentRecord)) {
				Number newValue = null;
				Number previous = previousValue;
				if (ServoyUtils.isContainedInFoundset(currentRecord, getDataProviderID())) {
					if (currentRecord.startEditing()) {
						if (isUsingFactor()) {
							newValue = numberValue;
							currentRecord.setValue(getDataProviderID(), newValue);
						} else {
							newValue = getCurrentValue();
							currentRecord.setValue(getDataProviderID(), newValue);
						}
						jsChangeRecorder.setValueChanged();
					}
				} else {
					previous = currentFoundset.getSelectedIndex() + 1;
					newValue = getCurrentValue();
					currentFoundset.setSelectedIndex(getCurrentValue()-1);
					jsChangeRecorder.setValueChanged();
				}
				if (ServoyUtils.isNotEmpty(onDataChange)) {
					ServoyUtils.runFunctionByName(onDataChange, app, new Object[] {previous, newValue});
				}
				previousValue = Utils.getAsDouble(newValue);
			}
		}
	}


	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.ISupportWebBounds#getWebBounds()
	 */
	public Rectangle getWebBounds() {
		Dimension localDimension = jsChangeRecorder.calculateWebSize(size.width, size.height, border, null, 0, null);
	    return new Rectangle(location, localDimension);
	}

	/**
	 * Will trigger an update if the text has changed
	 */
	public void testChanged() {
		if (previousValue != getNumberValue()) {
			jsChangeRecorder.setChanged();
		}
	}

	public void js_setBgcolor(String paramString) {
		setBackground(PersistHelper.createColor(paramString));
	}
	public String js_getBgcolor() {
		return (getBackground() == null) ? null : PersistHelper.createColorString(getBackground());
	}
	public void js_setFgcolor(String paramString) {
		setForeground(PersistHelper.createColor(paramString));
	}
	public String js_getFgcolor() {
		return (getForeground() == null) ? null : PersistHelper.createColorString(getForeground());
	}
	public void js_setBorder(String paramString) {
		setBorder(ComponentFactoryHelper.createBorder(paramString));
	}
	public void js_setFont(String paramString) {
		if (paramString != null) {
			setFont(PersistHelper.createFont(paramString));
		}
	}
	public void js_setFocusable(boolean focusable) {
		setFocusable(focusable);
	}
	public boolean js_isFocusable() {
		return isFocusable();
	}
	public void js_setInverted(boolean inverted) {
		setInverted(inverted);
	}
	public boolean js_isInverted() {
		return getInverted();
	}
	public void js_setMajorTickSpacing(int majorTickSpacing) {
		setMajorTicks(majorTickSpacing);
	}
	public int js_getMajorTickSpacing() {
		return getMajorTicks();
	}
	public void js_setMaximum(int maximum) {
		setMaximumValue(maximum);
	}
	public int js_getMaximum() {
		return getMaximumValue();
	}
	public void js_setMinimum(int minimum) {
		setMinimumValue(minimum);
	}
	public int js_getMinimum() {
		return getMinimumValue();
	}
	public void js_setMinorTickSpacing(int minorTickSpacing) {
		setMinorTicks(minorTickSpacing);
	}
	public int js_getMinorTickSpacing() {
		return getMinorTicks();
	}
	public void js_setOpaque(boolean opaque) {
		setOpaque(opaque);
	}
	public boolean js_isOpaque() {
		return isOpaque();
	}
	public void js_setOrientation(int orientation) {
		setOrientation(orientation);
	}
	public int js_getOrientation() {
		return getOrientation();
	}
	public void js_setPaintLabels(boolean paintLabels) {
		setPaintLabels(paintLabels);
	}
	public boolean js_getPaintLabels() {
		return getPaintLabels();
	}
	public void js_setPaintTicks(boolean paintTicks) {
		setPaintTicks(paintTicks);
	}
	public boolean js_getPaintTicks() {
		return getPaintTicks();
	}
	public void js_setPaintTrack(boolean paintTrack) {
		setPaintTrack(paintTrack);
	}
	public boolean js_getPaintTrack() {
		return getPaintTrack();
	}
	public void js_setSnapToTicks(boolean snapToTicks) {
		setSnapToTicks(snapToTicks);
	}
	public boolean js_getSnapToTicks() {
		return getSnapToTicks();
	}
	public void js_setToolTipText(String toolTipText) {
		setToolTipMessage(toolTipText);
	}
	public String js_getToolTipText() {
		return getToolTipText();
	}
	public String js_getName() {
		return getName();
	}
	public void js_setLocation(int x, int y) {
		setLocation(new Point(x, y));
	}
	public void js_setSize(int width, int height) {
		setSize(new Dimension(width, height));
	}
	public void js_setValue(Number val) {
		if (val != null) {
			setNumberValue(val.doubleValue());
		} else {
			setNumberValue(0);
		}
	}
	public Number js_getValue() {
		return getNumberValue();
	}
	public void js_setVisible(boolean visible) {
		setComponentVisible(visible);
	}
	public boolean js_isVisible() {
		return isVisible();
	}
	public void js_setEnabled(boolean enabled) {
		setComponentEnabled(enabled);
	}
	public boolean js_isEnabled() {
		return isEnabled();
	}
	public int js_getHeight() {
		return getWebBounds().height;
	}
	public int js_getWidth() {
		return getWebBounds().width;
	}
	public int js_getLocationX() {
		return getWebBounds().x;
	}
	public int js_getLocationY() {
		return getWebBounds().y;
	}
	
	public void js_setPrecisionFactor(int p) {
		setPrecision(p);
	}
	public int js_getPrecisionFactor() {
		return getPrecision();
	}
	public void js_setUsingDecimals(boolean newUsage) {
		setUsingDecimals(newUsage);
	}
	public boolean js_isUsingDecimals() {
		return isUsingDecimals();
	}

	/**
	 * @return the webStyleType
	 */
	public String getWebStyleType() {
		return this.webStyleType;
	}

	/**
	 * @param webStyleType the webStyleType to set
	 */
	public void setWebStyleType(String webStyleType) {
		this.webStyleType = webStyleType;
		jsChangeRecorder.setChanged();
	}

	/**
	 * @return the onDataChange
	 */
	public String getOnDataChange() {
		return this.onDataChange;
	}

	/**
	 * @param onDataChange the onDataChange to set
	 */
	public void setOnDataChange(String onDataChange) {
		this.onDataChange = onDataChange;
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.ISupportWebBounds#getPaddingAndBorder()
	 */
	public Insets getPaddingAndBorder() {
		return insets;
	}


	/* (non-Javadoc)
	 * @see com.servoy.j2db.ui.IProviderStylePropertyChanges#getStylePropertyChanges()
	 */
	public IStylePropertyChanges getStylePropertyChanges() {
		return jsChangeRecorder;
	}
	
}
